/*
 * Copyright 2016-2018 TVI Go Easy.
 * Created on 2018/1/30 15:26
 */
package com.tvi.cloud.organization.message;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import java.text.MessageFormat;

/**
 * 请在此写下该类的说明
 *
 * @author mechanic
 */
@Slf4j
@Component
@EnableBinding(Source.class)
public class SimpleSourceBean {

    private Source source;

    @Autowired
    public SimpleSourceBean(Source source) {
        this.source = source;
    }

    public void publishOrgChange(String action, String orgId) {
        log.debug(MessageFormat.format("Sending Kafka message {0} for Organization Id: {1}", action, orgId));
        //System.out.println(MessageFormat.format("Sending Kafka message {0} for Organization Id: {1}", action, orgId));
        OrganizationChangeModel change = new OrganizationChangeModel(
                OrganizationChangeModel.class.getTypeName(),
                action,
                orgId);

        source.output().send(MessageBuilder.withPayload(change).build());
    }


}
